package com.estate.struts.actions;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import com.estate.utils.FileUtil;

public class ImageUploadAction extends EstateSupport {
	
	private String Filedata;
	private String FiledataFileName;
	
	public String execute() throws Exception{
		File directory=new File(FileUtil.COMPANYSTUFF_FILE);
		System.out.println(this.getSession().getAttributeNames());
		String saveFile=directory+File.separator+FileUtil.getReplaceFileName(this.getFiledataFileName());
		System.out.println(saveFile);
		FileInputStream fis=new FileInputStream(this.getFiledata());
		
		if(!directory.exists()){
			directory.mkdir();
		}
		System.out.println("a");
		FileOutputStream fos=new FileOutputStream(saveFile);
		byte[] buffer=new byte[1024];
		int length;
		System.out.println("b");
		while((length=fis.read(buffer))>0){
			fos.write(buffer,0,length);
		}
		fis.close();
		fos.close();
		System.out.println("out load");
		return "test";
	}

	public void setFiledata(String filedata) {
		Filedata = filedata;
	}

	public String getFiledata() {
		return Filedata;
	}

	public void setFiledataFileName(String filedataFileName) {
		FiledataFileName = filedataFileName;
	}

	public String getFiledataFileName() {
		return FiledataFileName;
	}


}
